package com.mall4j.cloud.base.model;

import lombok.Data;

import java.io.Serializable;
import java.util.List;

@Data
public class BasePageVo<T> implements Serializable {

    private PageInfo<T> pageInfo;
    private List<T> dataList;

    public BasePageVo() {
    }

    public BasePageVo(PageInfo<T> pageInfo, List<T> dataList) {
        this.pageInfo = pageInfo;
        this.dataList = dataList;
    }

    @Data
    static class PageInfo<T> implements Serializable {

        public static final Integer DEFAULT_PAGE_SIZE = 200;
        public static final Integer DEFAULT_PAGE_NUM = 0;

        private Integer pageNum;
        private Integer pageSize;
        private Long totalElements;
        private Long totalPages;

        public PageInfo() {
            this.pageNum = DEFAULT_PAGE_NUM;
            this.pageSize = DEFAULT_PAGE_SIZE;
        }

        public PageInfo<T> setTotalElements(Long totalElements) {
            this.totalElements = Math.max(0, totalElements);
            this.totalPages = (totalElements + pageSize - 1) / pageSize;
            return this;
        }

    }
}


